package bigdata

import (
	"context"
	"errors"
	"git.mycaigou.com/gfyx/common/http_client"
	"git.mycaigou.com/gfyx/common/simplecopier"
)

/**
 * @Author: wenwb
 * @Description:
 * @File:  bigdata_repository
 * @Version: 1.0.0
 * @Date: 2024/01/08 10:47
 */

const (
	GetCompanyTargetUri = "/big-data/gfyx/company/target"
)

type bigDataRepository struct{}

func NewBigdataRepository() BigdataRepositoryIface {
	return &bigDataRepository{}
}

func (r *bigDataRepository) GetCompanyTarget(ctx context.Context, request *GetCompanyTargetRequest) (*GetCompanyTargetData, error) {
	client := http_client.NewDataServiceClient()
	response := GetCompanyTargetResponse{}
	requestMap, _ := simplecopier.StructToMapByJsonTag(request)
	_, _, errs := client.Post(ctx, GetCompanyTargetUri, requestMap, nil).EndStruct(&response)
	if len(errs) > 0 {
		return nil, errs[0]
	}
	if response.Success == false {
		return nil, errors.New(response.Message)
	}
	return response.Data, nil
}
